<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            margin-left: 10px;
        }
    </style>
</head>

<body>
    <div id="treeDiv"></div>
    <script>
        var treeData = [
            { "name": "A-1" },
            { "name": "A-2" },
            { "name": "A-3" },
            {
                "name": "A-4",
                "sub": [
                    { "name": "A-4-1" },
                    { "name": "A-4-2" },
                    {
                        "name": "A-4-3",
                        "sub": [
                            { "name": "A-4-3-1" },
                            { "name": "A-4-3-2" }
                        ]
                    }
                ]
            }
        ];
        let oTreeDiv = document.getElementById("treeDiv");
        function render(treeData, dom) {
            for (let i = 0; i < treeData.length; i++) {
                let ele = document.createElement("div");
                ele.innerHTML = treeData[i].name;
                dom.appendChild(ele);
                if (treeData[i].sub) {
                    render(treeData[i].sub, ele);
                }
            }
        }
        render(treeData, oTreeDiv);
    </script>
    <script>
        function domToImage() {

        }
        function debounce(func, delay) {
            let flag = true;
            return () => {
                if (flag) {
                    flag=false;
                    setTimeout(() => {
                        func()
                        flag = true;
                    }, delay);
                }
            }
        }
        let callback= debounce(domToImage, 500)
        a1.on("位置改变", callback)
        a1.on("大小改变", callback)
        a1.on("颜色改变",callback)
    </script>

</body>

</html>